﻿Imports System.Data.SqlClient
Imports System.Web
Imports System.Data.OleDb
Public Class UploadPictureToCruises
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\CruisesDB.accdb;Persist Security Info=True"
            Dim dt As New DataTable()
            Dim conn As New OleDbConnection(connectionString)




            Dim sql As String = "SELECT Max(CruisesTable.CId) AS MaxOfCId FROM CruisesTable;"




            Dim cmd As New OleDbCommand(sql, conn)
            If conn.State = Data.ConnectionState.Closed Then conn.Open()
            Dim dr As Integer = cmd.ExecuteScalar
            Session("cid") = dr
            conn.Close()
        End If
    End Sub

    
    Private Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
        Dim fileupload1 As FileUpload = CType(Me.FormView1.FindControl("fileupload1"), FileUpload)



        If fileupload1.HasFile = True Then
            '  fileupload1.SaveAs(MapPath(fileupload1.FileName))
            Dim filepath As String = fileupload1.PostedFile.FileName

            fileupload1.PostedFile.SaveAs(Server.MapPath(".\UserPictures\") & filepath)
            Session("fileupload") = "~\UserPictures\" & fileupload1.FileName

        End If
    End Sub
End Class